﻿using System;
using System.Linq.Expressions;
using System.Collections.Generic;


namespace Devtm.ServiceModel.Discovery.Collection
{
	
	public static class HelpersViews
	{

		#region Views


		/// <summary>
		/// Creates a view of the current list.
		/// </summary>
		/// <param name="filter">The filter.</param>
		/// <returns></returns>
		public static ViewCollection<T, TKey> GetView<T, TKey>(this ITableCollection<T, TKey> list, Expression<Func<T, bool>> filter)
		{
			return new ViewCollection<T, TKey>(list, filter);
		}

		/// <summary>
		/// Creates a view of the current list.
		/// </summary>
		/// <param name="subList">The filter.</param>
		/// <returns></returns>
		public static SubCollection<T2, TKey2, T, TKey> GetDerivedList<T2, TKey2, T, TKey>(this TableCollection<T, TKey> list, Expression<Func<T, T2>> subList)
		{
			return new SubCollection<T2, TKey2, T, TKey>(list, subList);
		}

		#endregion

		#region Indexes

		/// <summary>
		/// Creates a view of the current list.
		/// </summary>
		/// <param name="filter">The filter.</param>
		/// <returns></returns>
		public static TableCollection<T, TIndex> GetIndex<T, TKey, TIndex>(this ITableCollection<T, TKey> list, Expression<Func<T, TIndex>> columnName)
		{
			ITableCollection<T, TIndex> i = new IndexUniqueCollection<T, TKey, TIndex>(list, columnName);
			return (TableCollection<T, TIndex>)i;
		}


		public static IndexMultipleCollection<T, TKey, TIndex> GetIndexMultiple<T, TKey, TIndex>(this ITableCollection<T, TKey> list, Expression<Func<T, TIndex>> columnName)
		{
			IndexMultipleCollection<T, TKey, TIndex> i = new IndexMultipleCollection<T, TKey, TIndex>(list, columnName);
			return i;
		}

		#endregion

	}

}
